<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>

<div class="panel_container">
    <div class="panel">
        <form id="formId" method="post" action="${ctx}/discount/addDiscount">
            <div class="panel_header">
                <div><h2>添加贴现</h2></div>
            </div>
            <div class="panel_body">
                <div>
                    <div>
                        <div class="info_item"><span>票据内部编号:</span><b>*</b>
                            <input type="text" name="pjnbbh"  />
                        </div>

                        <div class="info_item"><span>金融机构编码:</span><b>*</b>
                            <select name="orgId" id="orgId">
                                <option value="">--请选择--</option>
                                <c:forEach var="entry" items="${orgList}">
                                    <option value="${entry.id}" >${entry.orgName}</option>
                                </c:forEach>
                            </select>
                        </div>

                        <div class="info_item"><span>数据时间:</span><b>*</b>
                            <input type="text" name="sjsj" id="sjsj" />
                        </div>
                    </div>

                    <div>
                        <div class="info_item"><span>企业组织机构代码:</span><b>*</b>
                            <input type="text" name="zzjgdm" />
                        </div>

                        <div class="info_item"><span>贴现申请人名称:</span><b>*</b>
                            <input type="text" name="txsqrmc" />
                        </div>

                        <div class="info_item"><span>票据种类:</span><b>*</b>
                            <tags:select name="pjzl" id="pjzl" tableName="T_SYSTEM_DICT" whereClause="CODE_TYPE_ID = 15 "  />
                        </div>
                    </div>

                    <div>
                        <div class="info_item"><span>贴现金额:</span><b>*</b>
                            <input type="text" name="txje" />
                        </div>

                        <div class="info_item"><span>承兑人/行名称:</span><b>*</b>
                            <input type="text" name="cdhmc" />
                        </div>

                        <div class="info_item"><span>币种:</span><b>*</b>
                            <tags:select name="bz" id="bz" tableName="T_SYSTEM_DICT" whereClause="CODE_TYPE_ID = 9 "  />
                        </div>
                    </div>

                    <div>
                        <div class="info_item"><span>折算成人民币的金额:</span>
                            <input type="text" name="zsrmb" />
                        </div>

                        <div class="info_item"><span>折算成美元的金额:</span>
                            <input type="text" name="zsmy"  />
                        </div>

                        <div class="info_item"><span>贴现利率(%):</span><b>*</b>
                            <input type="text" name="txll"  />
                        </div>
                    </div>

                    <div>
                        <div class="info_item"><span>贴现日:</span><b>*</b>
                            <input type="text" name="txrq" id="txrq" />
                        </div>

                        <div class="info_item"><span>承兑到期日:</span><b>*</b>
                            <input type="text" name="cdrq" id="cdrq" />
                        </div>

                        <div class="info_item"><span>票面金额:</span><b>*</b>
                            <input type="text" name="pmje" />
                        </div>
                    </div>

                    <div>
                        <div class="info_item"><span>五级分类:</span><b>*</b>
                            <tags:select name="wjfl" id="wjfl" tableName="T_SYSTEM_DICT" whereClause="CODE_TYPE_ID = 12 "  />
                        </div>

                        <div class="info_item"><span>承兑行（人）所在地区:</span><b>*</b>
                            <tags:select name="cdhdq" id="cdhdq" tableName="T_SYSTEM_DICT" whereClause="CODE_TYPE_ID = 19 "  />
                        </div>
                    </div>


                </div>
            </div>
            <div class="panel_footer">
                <div>
                    <input type="submit" value="保存" class="btn_blue" id="btn_save"/>
                    <input type="button" value="返回" class="btn_blue" id="btn_back"/>
                </div>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">

    function goBack(){
        linkTo("${ctx}/discount/toDiscount");
    }

    $(function () {

        $('#sjsj').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yymm'
        });
        $('#txrq').datepicker();
        $('#cdrq').datepicker();

        $("#btn_back").bind("click",goBack);

        $("#formId").validate({
            rules:{
                zzjgdm: "required",
                txsqrmc: "required",
                sjsj: "required",
                pjzl: "required",
                cdhmc: "required",
                bz: "required",
                txje:{
                    required:true,
                    number:true,
                    min:0,
                    max:9999999999999.99
                },
                txrq: "required",
                cdrq: "required",
                txll:{
                    required:true,
                    number:true,
                    min:0,
                    max:99.9999
                },
                pmje:{
                    required:true,
                    number:true,
                    min:0,
                    max:9999999999999.99
                },
                wjfl: "required",
                cdhdq: "required",
                pjnbbh:"required"
            },
            messages:{
                zzjgdm: "组织机构代码不能为空",
                txsqrmc: "贴现申请人名称不能为空",
                sjsj: "数据时间不能为空",
                pjzl: "票据种类不能为空",
                cdhmc: "承兑人/行名称不能为空",
                bz: "币种不能为空",
                txje:{
                    number:"必须是数字",
                    required:"贴现金额不能为空",
                    min:"最小值0",
                    max:"最大值9999999999999.99"
                },
                txrq: "贴现日不能为空",
                cdrq: "承兑到期日不能为空",
                txll:{
                    required:"贴现利率不能为空",
                    number:"必须是数字",
                    min:"最小值0",
                    max:"最大值99.9999"
                },
                pmje:{
                    number:"必须是数字",
                    required:"票面金额不能为空",
                    min:"最小值0",
                    max:"最大值9999999999999.99"
                },
                wjfl: "五级分类不能为空",
                cdhdq: "承兑行（人）所在地区不能为空",
                pjnbbh:"票据内部编号不能为空"
            },
            submitHandler: function(form) {
                $(form).ajaxSubmit({
                    success: function(response) {
                        $.prompt("保存成功");
                        window.setTimeout(function(){
                            goBack();
                        },2000);
                    },

                    error: function(response){
                        $.prompt("保存失败:"+response,"错误");
                    }
                });
            }
        });
    });

</script>

